#!/bin/bash  -e

function info() {
echo Usage: `basename $0` in.bam in.bed num
exit 65
}

while getopts  ":i:p:" opts
do
        case  $opts  in
        i) interval=$OPTARG;;
		p) out_prefix=$OPTARG;;
		*) info;;
        esac
done
shift $(($OPTIND - 1))


if [ $# -lt 3 ]; then info; fi

. /mnt/ilustre/app/medical/tools/.var



bam=$1

cat $2|cut -f1-3 >$out_prefix.bed

num=$3

bed-split.py $out_prefix.bed $num

for i in $(seq $num); do

subq.sh -F -m3 -p3 -nsamseg.$i extract_bam_bed.sh -p$out_prefix $bam $out_prefix.$i.bed

done

. $cmd_done